#ifndef DESKTOP_H
#define DESKTOP_H

#include <QMainWindow>
#include <QWidget>
#include <QVBoxLayout>
#include <QTextStream>
#include <QMessageBox>
#include <QFileDialog>
#include <QStandardPaths>
#include <QProgressDialog>
#include <QFutureWatcher>
#include <QFuture>
#include <QObject>
#include <QVector>
#include "infoprint/infoprint.h"
#include "tabframe/tabwidgetframe.h"
#include "functionbutton/functionbutton.h"
#include "view_global.h"
#include "exporter/spectrumexporter.h"
#include "dataspecification.h"

/**
 * @brief 主窗口类
 * 
 * 该类负责管理整个应用程序的主窗口，包括：
 * - 标签页管理
 * - 信息打印区域
 * - 功能按钮区域
 * - 文件操作
 */
class VIEW_EXPORT Desktop : public QMainWindow
{
    Q_OBJECT
public:
    explicit Desktop(QWidget* parent = nullptr);
    ~Desktop();

private slots:
    void loadFile(const QString& filePath);
    void saveFile();
    void handleLoadSuccess(DataSpecificationGW::DataSpecification* specification);
    void handleLoadError();

public slots:
    void onFileSelected(QString filePath);
    void onClearAll();
    void onRefresh();
    void onExport();
    void onRecentFileSelected(QString filePath);

public:
    void paintEvent(QPaintEvent *event);

private:
    void initUI();
    void setupConnections();
    QString getSaveFilePath(const QString& defaultName = QString(), 
                          const QString& filter = QString());

    void InitTabWidget();
    void InitInfoPrint();
    void InitFuncBtn();
    bool validateFile(const QString& filePath);
    void showProgress(const QString& title, int duration);

    // CSV导出相关方法
    void exportAEAmpData(QTextStream& out, DataSpecificationGW::Spectrum* spectrum);
    void exportAEPhaseData(QTextStream& out, DataSpecificationGW::Spectrum* spectrum);
    void exportAEPulseData(QTextStream& out, DataSpecificationGW::Spectrum* spectrum);
    void exportAEWaveData(QTextStream& out, DataSpecificationGW::Spectrum* spectrum);

private:
    TabWidgetFrame* m_tabFrame;
    InfoPrint* m_infoPrint;
    FunctionButton* m_functionBtn;
    QVBoxLayout* m_mainLayout;
    QString m_currentFilePath;
    DataSpecificationGW::DataSpecification* specification;
};

#endif // DESKTOP_H
